namespace HD.Model.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class CreateDB : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Employees",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 20),
                        Gender = c.String(),
                        Description = c.String(),
                        HappinessIndex = c.Int(nullable: false),
                        Picture = c.String(),
                        BirthDay = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.News",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false, maxLength: 50),
                        Content = c.String(nullable: false, maxLength: 500),
                        PublishDate = c.DateTime(nullable: false),
                        EmployeeId = c.Int(nullable: false),
                        NewsType = c.Int(nullable: false),
                        TimeStamp = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Employees", t => t.EmployeeId, cascadeDelete: true)
                .Index(t => t.EmployeeId);
            
            CreateTable(
                "dbo.Departments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 20),
                        Description = c.String(maxLength: 20),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.TaskInitiations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        WeekDate = c.String(),
                        TaskValue = c.String(),
                        EmployeeId = c.Int(nullable: false),
                        TaskNameId = c.Int(nullable: false),
                        TaskId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Employees", t => t.EmployeeId, cascadeDelete: true)
                .ForeignKey("dbo.Tasks", t => t.TaskId, cascadeDelete: true)
                .Index(t => t.EmployeeId)
                .Index(t => t.TaskId);
            
            CreateTable(
                "dbo.Tasks",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        Decription = c.String(nullable: false, maxLength: 50),
                        DefaultValue = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.TaskCompleteds",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CompletedValue = c.Int(nullable: false),
                        Date = c.DateTime(nullable: false),
                        TaskId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Tasks", t => t.TaskId, cascadeDelete: true)
                .Index(t => t.TaskId);
            
            CreateTable(
                "dbo.Follows",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        PostId = c.Int(nullable: false),
                        EmployeeId = c.Int(nullable: false),
                        Comments = c.String(maxLength: 200),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Posts", t => t.PostId, cascadeDelete: true)
                .ForeignKey("dbo.Employees", t => t.EmployeeId, cascadeDelete: true)
                .Index(t => t.PostId)
                .Index(t => t.EmployeeId);
            
            CreateTable(
                "dbo.Posts",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false, maxLength: 50),
                        CreateDate = c.DateTime(nullable: false),
                        Content = c.String(nullable: false, maxLength: 200),
                        Type = c.String(),
                        EmployeeId = c.Int(nullable: false),
                        PostsTypeId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Employees", t => t.EmployeeId, cascadeDelete:false)
                .ForeignKey("dbo.PostsTypes", t => t.PostsTypeId, cascadeDelete: true)
                .Index(t => t.EmployeeId)
                .Index(t => t.PostsTypeId);
            
            CreateTable(
                "dbo.PostsTypes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        Description = c.String(maxLength: 500),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.DepartmentEmployees",
                c => new
                    {
                        Department_Id = c.Int(nullable: false),
                        Employee_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Department_Id, t.Employee_Id })
                .ForeignKey("dbo.Departments", t => t.Department_Id, cascadeDelete: true)
                .ForeignKey("dbo.Employees", t => t.Employee_Id, cascadeDelete: true)
                .Index(t => t.Department_Id)
                .Index(t => t.Employee_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.DepartmentEmployees", new[] { "Employee_Id" });
            DropIndex("dbo.DepartmentEmployees", new[] { "Department_Id" });
            DropIndex("dbo.Posts", new[] { "PostsTypeId" });
            DropIndex("dbo.Posts", new[] { "EmployeeId" });
            DropIndex("dbo.Follows", new[] { "EmployeeId" });
            DropIndex("dbo.Follows", new[] { "PostId" });
            DropIndex("dbo.TaskCompleteds", new[] { "TaskId" });
            DropIndex("dbo.TaskInitiations", new[] { "TaskId" });
            DropIndex("dbo.TaskInitiations", new[] { "EmployeeId" });
            DropIndex("dbo.News", new[] { "EmployeeId" });
            DropForeignKey("dbo.DepartmentEmployees", "Employee_Id", "dbo.Employees");
            DropForeignKey("dbo.DepartmentEmployees", "Department_Id", "dbo.Departments");
            DropForeignKey("dbo.Posts", "PostsTypeId", "dbo.PostsTypes");
            DropForeignKey("dbo.Posts", "EmployeeId", "dbo.Employees");
            DropForeignKey("dbo.Follows", "EmployeeId", "dbo.Employees");
            DropForeignKey("dbo.Follows", "PostId", "dbo.Posts");
            DropForeignKey("dbo.TaskCompleteds", "TaskId", "dbo.Tasks");
            DropForeignKey("dbo.TaskInitiations", "TaskId", "dbo.Tasks");
            DropForeignKey("dbo.TaskInitiations", "EmployeeId", "dbo.Employees");
            DropForeignKey("dbo.News", "EmployeeId", "dbo.Employees");
            DropTable("dbo.DepartmentEmployees");
            DropTable("dbo.PostsTypes");
            DropTable("dbo.Posts");
            DropTable("dbo.Follows");
            DropTable("dbo.TaskCompleteds");
            DropTable("dbo.Tasks");
            DropTable("dbo.TaskInitiations");
            DropTable("dbo.Departments");
            DropTable("dbo.News");
            DropTable("dbo.Employees");
        }
    }
}
